package com.njtcedu.microblog.website.user.repository;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.stereotype.Repository;
import com.njtcedu.microblog.common.entity.User;
import com.njtcedu.microblog.common.repository.AbstractRepository;
import com.njtcedu.microblog.common.repository.RowMapper;

@Repository
public class WebSiteUserRepository extends AbstractRepository {

	public User get(Integer userId) {
		return hibernateAccess.get(User.class, userId);
	}
	
	public User load(Integer userId) {
		return jdbcAccess.findUniqueResult("select u.id, u.account, u.password from user u where id = ?", new RowMapper<User>() {

			@Override
			public User mapRow(ResultSet resultSet, int rowNum) throws SQLException {
				User user = new User();
				user.setId(resultSet.getInt("id"));
				user.setAccount(resultSet.getString("account"));
				user.setPassword(resultSet.getString("password"));
				return user;
			}
		}, userId);
	}
}
